package com.ruoyi.common.enums;

import java.util.HashMap;

/**
 * OrderStateEnum
 * @author caoes
 */
public enum OrderStatusEnum {
    UNPAY(1,"未支付"),
    PAID(2,"已支付"),
    CANCEL_PAYMENT(3, "取消支付"),
    TIMEOUT_PAYMENT(4, "支付超时");

    private static HashMap<Integer, OrderStatusEnum> ORDER_STATUS_STATUS_MAP = new HashMap<>();

    static {
        for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
            ORDER_STATUS_STATUS_MAP.put(orderStatusEnum.code, orderStatusEnum);
        }
    }

    private final int code;
    private final String descp;

    OrderStatusEnum(int code, String descp) {
        this.code = code;
        this.descp = descp;
    }

    public int getCode() {
        return code;
    }

    public String getDescp() {
        return descp;
    }

    public static OrderStatusEnum of(int code) {
        if (ORDER_STATUS_STATUS_MAP.containsKey(code)) {
            return ORDER_STATUS_STATUS_MAP.get(code);
        }
        throw new IllegalArgumentException("invalid code : " + code);
    }
}
